import React from 'react'
import { connect } from 'dva'
import PropTypes from 'prop-types'
import { Modal } from 'antd'
import BaseInfo from './BaseInfo'
import styles from './XModel.less' // eslint-disable-line

@connect(({ projectHall, loading }) => ({
  projectHall,
  loading: loading.effects['projectHall/fetchProject'],
}))
class XModel extends React.PureComponent {

  onCancel = e => {
    e.preventDefault()

    const { dispatch } = this.props
    dispatch({
      type: 'projectHall/save',
      payload: {
        visible: false
      }
    })
  }

  render() {
    const { projectHall, width, closable } = this.props
    const { visible, profile = {} } = projectHall
    const title = profile.project_id ? '编辑项目' : '新增项目'

    return (
      <Modal
        visible={visible}
        title={title}
        closable={closable}
        footer={null}
        width={width}
        onCancel={this.onCancel}
        destroyOnClose="true"
      >
        <BaseInfo />
      </Modal>
    )
  }
}

XModel.propTypes = {
  width: PropTypes.number,
  closable: PropTypes.bool
}

XModel.defaultProps = {
  width: 1000,
  closable: true
}

export default XModel